'use strict';

let fs = require("fs");

let {defineModel,DataTypes,sequelize} = require("../db");

function findfile(){
    let file = fs.readdirSync(__dirname);
    return file.filter(name=>{
        return name.endsWith(".js") && name !== "index.js";
    })
}

function registerModel(files){
    let obj = {};
    files.forEach(file => {
        let attrs = file.substring(0,file.length-3);
        console.log(attrs);
        obj[attrs] = require(__dirname+"/"+file); 
    });
    
    return obj;
}

let files = findfile();
let obj = registerModel(files);

obj.sync=async ()=>{
    return sequelize.sync({force:true})
}

module.exports = obj;